home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / include / PAGEHASH.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  8.9 KB  |  277 lines

  1. #ifndef __PAGEHASH_H__
  2. #define __PAGEHASH_H__
  3.  
  4. /*
  5.  *   $RCSfile: PAGEHASH.h,v $  
  6.  *   $Revision: 1.1.1.1 $  
  7.  *   $Date: 1996/05/04 21:55:07 $      
  8.  */ 
  9.  
  10. /**********************************************************************
  11. * EXODUS Database Toolkit Software
  12. * Copyright (c) 1991 Computer Sciences Department, University of
  13. *                    Wisconsin -- Madison
  14. * All Rights Reserved.
  15. *
  16. * Permission to use, copy, modify and distribute this software and its
  17. * documentation is hereby granted, provided that both the copyright
  18. * notice and this permission notice appear in all copies of the
  19. * software, derivative works or modified versions, and any portions
  20. * thereof, and that both notices appear in supporting documentation.
  21. *
  22. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  23. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  24. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  25. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  26. *
  27. * The EXODUS Project Group requests users of this software to return 
  28. * any improvements or extensions that they make to:
  29. *
  30. *   EXODUS Project Group 
  31. *     c/o David J. DeWitt and Michael J. Carey
  32. *   Computer Sciences Department
  33. *   University of Wisconsin -- Madison
  34. *   Madison, WI 53706
  35. *
  36. *     or exodus@cs.wisc.edu
  37. *
  38. * In addition, the EXODUS Project Group requests that users grant the 
  39. * Computer Sciences Department rights to redistribute these changes.
  40. **********************************************************************/
  41. #include "resources.h"
  42. #include "error.h"
  43. #include "io.h"
  44. #include "object.h"
  45. #include "tid.h"
  46. #include "bf_macro.h"
  47. #include "trace.h"
  48.  
  49. class PAGEHASH {
  50. public:
  51.  
  52.     BOOL         Dump(FILE *f);
  53.     PID         *keylocation (int unique, PID **unused);
  54.     LISTELEMENT *listlocation (int unique);
  55.     void         ReInit();
  56.     void         Init();
  57.  
  58. #ifdef SERVER_MAKE
  59.     /* stuff specific to SERVER side */
  60.  
  61.     /*
  62.      *    This structure is used to represent a page in the buffer pool
  63.      *    There is one of these per page that is resident
  64.      */
  65.     UONE        flags;            /* flags for this page                */
  66. #define H_FREE            0x0        /* The page hash structure is free    */
  67. #define H_DIRTY            0x1        /* The page is dirty                */
  68. #define H_LOG            0x2        /* The page is a log page            */
  69. #define H_LRC_REPAIR    0x4        /* The page having its lrc repaired.
  70.                                    In this case the page has firstLRC
  71.                                    and firstLSN's set, but it is not
  72.                                    marked H_DIRTY                    */
  73. #define H_INDEX            0x5
  74. #define H_TEMP            0x6        /* diff meaning fromn cli side */
  75. #define H_NEW            0x7        /* used on client side only */
  76. #define H_INVALID       0x0   /* USED ONLY ON CLIENT SIDE */
  77.  
  78.     UONE        pageType;        /* the type of page                    */
  79.                                 /*     values are PAGE_xxx    io.h        */
  80. #define PPAGE_TYPE(ph) ((ph)->pageType)
  81. #define PSET_PAGE_TYPE(ph,typ) ((ph)->pageType = (typ))
  82.  
  83.     UONE        blockCount;        /* number of blocks in this page    */
  84.     UTWO        bufIndex;        /* index of page in BufTable        */
  85.     char        *bufFrame;        /* pointer to the buffer frame        */
  86. #define PBUFFRAME(ph) ((ph)->bufFrame)
  87. #define BUFFRAME(ph) ((ph).bufFrame)
  88.  
  89.     BUFINFO        *bufInfo;        /* pointer to buf info entry        */
  90.     SEMAPHORE    semaphore;
  91.     LATCH        latch;
  92.     LISTELEMENT    clientDirtyList;/* page received from client        */
  93.     int            pendingOpCount;    /* number of pending operations        */
  94.     LSN            lsn;            /* LSN of first log record to dirty */
  95.  
  96. #else
  97.     /* stuff specific to CLIENT side */
  98.     /*
  99.      * If the hash entry is for a page that belongs to a chunk, then the 
  100.      * entry will have a non-NULL chunkDesc field, pointing to the CHUNKDESC
  101.      * structure that the page is a part of.
  102.      * 
  103.      * If the hash entry is for a slotted page, then the entry
  104.      * will have a non-NULL pageInfo field, pointing to the PAGEINFO 
  105.      * structure associated with the page.
  106.      * Hanging off the PAGEINFO structure are page user descriptors, which
  107.      * are used much like chunk user descriptors, except they are used to
  108.      * reference small objects within the page.
  109.      */
  110.  
  111.     /*
  112.      *  Page type is embedded in flags on client side for historic reasons
  113.      *  see client's bf.h
  114.      */
  115.     UTWO           flags;          /* type of structure & flags(e.g., dirty)   */
  116. /*
  117.  *  Values for PAGEFLAGS type (flags in the PAGEHASH struct)
  118.  *  Page type is embedded in flags for historic reasons... mucho code
  119.  *  checks flags to get the page type.
  120.  *  Henceforth code should check page type by using the macro
  121.  *  PAGE_TYPE(pageHash), which inspects only the lower byte of flags.
  122.  *  Some day, when all the code is converted, we can remove the
  123.  *  types to a u_char of their own.
  124.  */
  125. #define H_FREE      PAGE_GENERIC    /* The page hash structure is free  */
  126. #define H_SLOTTED   PAGE_SLOTTED     /* a slotted (small object) page    */
  127. #define H_LARGE     PAGE_LARGENODE    /* a control page of a large object */
  128. #define H_CHUNK     PAGE_LARGEDATA    /* a data page of a large object    */
  129. #define H_LOG       PAGE_LOG        /* The page is a log page           */
  130. #define H_INDEX     PAGE_INDEX        /* btree index page                 */
  131. #define H_INDEXDESC    PAGE_INDEXDESC    /* an index descriptor page         */
  132. #define H_DIRTY     0x100           /* The page is dirty                */
  133. #define H_INVALID   0x200           /* The page is here but perhaps out of
  134.                                         date*/
  135. #define H_TEMP       0x400           /* temporarily put in hash table; 
  136.                                     a kludge on server side; 
  137.                                     page on temp volume on client side  */
  138. #define H_NEW       0x800           /* The page is newly allocated - used
  139.                                      * on the client side only */
  140.  
  141. #define PPAGE_TYPE(ph) ((ph)->flags & 0xff)
  142. #define PSET_PAGE_TYPE(ph,typ) ((ph)->flags = (typ))
  143.  
  144.     PAGEINFO    *pageInfo;      /* ptr to page's info                       */
  145. #define PBUFFRAME(ph) ((ph)->pageInfo->bufFrame)
  146. #define BUFFRAME(ph) ((ph).pageInfo->bufFrame)
  147.  
  148.     LISTELEMENT dirtyList;      /* list of dirty pages in the transaction   */
  149.     TID         readLock;
  150.     TID         writeLock;
  151.  
  152. #define IS_VALID(__phash) \
  153. ((__phash->readLock!=NULL_TID)&&(LIST_MEMBER(&(__phash->hashList.hashList))))
  154.  
  155. #define IS_INVALID(__phash) \
  156. ((__phash->readLock==NULL_TID)||(!LIST_MEMBER(&(__phash->hashList.hashList))))
  157.  
  158.     /* added for client operation logging - MJF */
  159.     LSN            firstLSN;     /* approximate firstLSN for the page        */
  160.     LRC            firstLRC;     /* the LRC for the first opeation applied
  161.                                                                 to the page        */
  162.     int            releaseCnt;
  163.     int            releaseLimit;
  164.  
  165. #endif
  166.  
  167.  
  168.     /* stuff common to SERVER and CLIENT */
  169.     LIST        memberList;        /* list of chunks or groups            */
  170.     PAGEHASHQ   hashList;       /* hash queue list element                  */
  171.     PAGE2SIZE   page2size;      /* size of the page in blocks               */
  172.     FORCEMARK   forceMark;
  173.     FORCEMARK   firstMark;
  174.     TWO         memberCount;    /* number of chunks or groups               */
  175.     LRC            lrc;            /* LRC of first log record to dirty */
  176.     MAGIC       magic;          /* magic number for verification            */
  177. /*
  178.  *  define magic number
  179.  */
  180. #define PAGEHASH_MAGIC      0x76129ad5
  181.  
  182. }; /* end class PAGEHASH */
  183.  
  184. #endif __PAGEHASH_H__
  185.  
  186. #ifdef __BF_PageHash_C__
  187.  
  188. #ifndef __BF_PageHash_C__Defined
  189. #define __BF_PageHash_C__Defined
  190.  
  191. BOOL 
  192. PAGEHASH:: Dump(FILE *f) {
  193.     fprintf(f,  "DUMP OF PAGEHASH 0x%x\n", this);
  194.     fprintf(f, 
  195.         "PAGEHASH flags 0x%x, page2size %d, magic 0x%x\n",
  196.         this->flags, this->page2size, this->magic);
  197.     fprintf(f, "\t pageType %d, lrc %d.%d pid %d.%d\n",
  198.         PPAGE_TYPE(this), 
  199.         this->lrc.wrapCount, this->lrc.count,
  200.         this->hashList.hashPid.page,
  201.         this->hashList.hashPid.volid);
  202.     return FALSE;
  203.  
  204. PID *
  205. PAGEHASH:: keylocation (int unique, PID **unused) {
  206.     switch(unique) {
  207.     case PAGEHASH_TABLE:
  208.         return &(hashList.hashPid); 
  209.     default:
  210.         TRPRINT(TR_BF, TR_LEVEL_1, ("bad unique value: %d\n", unique));
  211.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  212.         /* to prevent the compiler from complaining 
  213.             about no return value: */
  214.         return &(hashList.hashPid); 
  215.     }
  216. }
  217.  
  218. LISTELEMENT *
  219. PAGEHASH:: listlocation (int unique) {
  220.     switch (unique) {
  221.     case PAGEHASH_TABLE:
  222.     case PAGEHASH_POOL:
  223.         return &(hashList.hashList); 
  224.     case DIRTY_LIST:
  225. #ifdef SERVER_MAKE
  226.         return &(clientDirtyList); 
  227. #else SERVER_MAKE
  228.         return &(dirtyList); 
  229. #endif SERVER_MAKE
  230.     case MEMBER_LIST:
  231.         return &(memberList); 
  232.     default:
  233.         TRPRINT(TR_BF, TR_LEVEL_1, ("bad unique value: %d\n", unique));
  234.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  235.         /* to prevent the compiler from 
  236.         complaining about no return value: */
  237.         return &(hashList.hashList); 
  238.     }
  239. }
  240.  
  241. void 
  242. PAGEHASH:: ReInit() {
  243.     this->flags = H_FREE;
  244.     this->page2size = MIN_PAGE2SIZE;
  245.     PSET_PAGE_TYPE(this, PAGE_GENERIC);
  246.     this->lrc = LrcNone;
  247.     this->hashList.hashPid = PidNone;
  248.     this->memberCount = 0;
  249. #ifndef SERVER_MAKE
  250.     this->readLock = 
  251.         this->writeLock = NULL_TID;
  252.     this->releaseCnt = 
  253.         this->releaseLimit = 0;
  254. #endif SERVER_MAKE
  255. }
  256.  
  257. void 
  258. PAGEHASH:: Init() {
  259.     initializeListElement(this->listlocation(PAGEHASH_POOL),
  260.                                         (char *)this);
  261.     initializeListElement(this->listlocation(DIRTY_LIST), 
  262.                                         (char *)this);
  263.     initializeList(this->listlocation(MEMBER_LIST));
  264.     INIT_PAGEHASH_MAGIC( this );
  265.  
  266. #ifdef SERVER_MAKE
  267.     initializeLatch( &(this->latch) );
  268.     initializeSemaphore( &(this->semaphore), FALSE );
  269. #endif SERVER_MAKE
  270.  
  271.     this->ReInit();
  272. }
  273. #endif __BF_PageHash_C__Defined
  274. #endif __BF_PageHash_C__
  275.  
  276.